package util;
import java.net.HttpRetryException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

import model.Category;

public class HTMLConverter {
	
	//used in recipe.jsp
	public static String loadNumberListToComboBox(String name, int maxValue) {
		String html = "<SELECT NAME=\"" + name + "\">";		
		for(int i = 0; i < maxValue; i++){
			  if(i < 10)
              	html += "<OPTION VALUE=\"0"+i+"\">0"+i+"</OPTION>";
			  else
				html += "<OPTION VALUE=\""+i+"\">"+i+"</OPTION>";
		}
		html += "</SELECT>";
		
		return html;
	}
	
	//used in recipe.jsp
	public static String loadCategoryListToComboBox(String name, String firstItemName, List<Category> categoryList, HttpServletRequest request) {
		String html = "<SELECT NAME=\"" + name + "\">";		
		html += "<OPTION VALUE=\"0\">" + firstItemName + "</OPTION>";
		
		if (categoryList != null) {
			for (int i = 0; i < categoryList.size(); i++) {
				Category category = categoryList.get(i);
				
				if (("" + category.getId()).equals(request.getParameter(name))) {
					html += "<OPTION VALUE=\"" + category.getId() + "\" selected=\"selected\">";
				}
				else {
					html += "<OPTION VALUE=\"" + category.getId() + "\">";
				}			
				html += category.getName();
				html += "</OPTION>";
			}
		}
		html += "</SELECT>";
		
		return html;
	}
	
	//used in detailsRecipe.jsp (time of preparation and time of cooking)
	public static String loadNumberToTime(int value, String typeOfTime){
		String html = "";	
		if(value != 0)
		{
			if (value <= 60)
				html = "<div class=\"position3\"><label>" + typeOfTime + " "+ String.valueOf(value)+" minute(s)</label><br/></div>";
			else 
				html = "<div class=\"position3\"><label>" + typeOfTime + " "+ String.valueOf(value/60) + " heure(s) " + String.valueOf(value%15) +" minute(s)</label><br/></div>";
		}	
		return html;
	}
}
